/* eslint-disable prefer-destructuring */
const host = require('./host')
const ENV_TYPE = process.env.ENV_TYPE || 'dev'
const { APP_TYPE } = process.env

let TARO_ENV = 'rn'
const command = process.env.npm_lifecycle_event
if (command && command.indexOf(':') > 0) {
  TARO_ENV = command.split(':')[1]
}
// const TARO_ENV = process.env.npm_lifecycle_event.split(':')[1]
const HOST_URL = host[TARO_ENV][ENV_TYPE || 'dev']
const SOCKET_URL = host.websocket[ENV_TYPE || 'dev']
const OSS_URL = host.oss[ENV_TYPE || 'dev']
const PRIVATE_OSS = host.privateOSS[ENV_TYPE || 'dev']
const CLOUD_ID = host.cloudId[ENV_TYPE || 'dev']
const DOMAIN_URL = host.domain[ENV_TYPE || 'dev']
const MEDLINC_DOMAIN_URL = host.medLincDomain[ENV_TYPE || 'dev']
const APP_ID = host[TARO_ENV].appId
const WEAPP_ANALYTICS_ID = host.weappAnalyticsId[ENV_TYPE || 'dev']
const H5_ANALYTICS_ID = host.h5AnalyticsId[ENV_TYPE || 'dev']
const VIDEO_URL = host.video[ENV_TYPE || 'dev']
const STORE_APP_ID = host[TARO_ENV].storeAppId

module.exports = {
  env: {
    NODE_ENV: '"production"'
  },
  defineConstants: {
    APP_TYPE: `"${APP_TYPE}"`,
    CARE_ENV_TYPE: `"${ENV_TYPE}"`,
    BASE_URL: `"${HOST_URL}"`,
    SOCKET_URL: `"${SOCKET_URL}"`,
    OSS_URL: `"${OSS_URL}"`,
    PRIVATE_OSS: `"${PRIVATE_OSS}"`,
    CLOUD_ID: `"${CLOUD_ID}"`,
    DOMAIN_URL: `"${DOMAIN_URL}"`,
    MEDLINC_DOMAIN_URL: `"${MEDLINC_DOMAIN_URL}"`,
    APP_ID: `"${APP_ID}"`,
    VIDEO_URL: `"${VIDEO_URL}"`,
    WEAPP_ANALYTICS_ID: `"${WEAPP_ANALYTICS_ID}"`,
    H5_ANALYTICS_ID: `"${H5_ANALYTICS_ID}"`,
    SHOW_VISITED_HOSPITAL: false,
    STORE_APP_ID: `"${STORE_APP_ID}"`
  },
  // copy: {
  //   patterns: [
  //     { from: 'devops/ajKKz9Epna.txt', to: 'dist/weapp/pages/patient/ajKKz9Epna.txt' } // 指定需要 copy 的文件
  //   ]
  // },
  mini: {},
  h5: {
    /**
     * 如果h5端编译后体积过大，可以使用webpack-bundle-analyzer插件对打包体积进行分析。
     * 参考代码如下：
     * webpackChain (chain) {
     *   chain.plugin('analyzer')
     *     .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, [])
     * }
     */
    // output: {
    //   chunkFilename: './chunk/[chunkhash:4].js',
    // }
  }
}
